#include <graphics/MD2Model.h>

namespace ne
{
    MD2Model::MD2Model()
        : m_pVertexList(0),
          m_pNormalList(0),
          m_pTexCoordList(0),
          m_pVertexIndexList(0),
          m_pNormalIndexList(0),
          m_pTexCoordIndexList(0),
          m_pTexture(0),
          m_iFrameNum(0),
          m_iFrameSize(0)
    {
    }

    void MD2Model::setVertexList(VertexList *list)
    {
        if (m_pVertexList != 0)
        {
            delete m_pVertexList;
            m_pVertexList = 0;
        }
        m_pVertexList = list;
    }

    MD2Model::VertexList* MD2Model::getVertexList() const
    {
        return m_pVertexList;
    }

    void MD2Model::setNormalList(NormalList *list)
    {
        if (m_pNormalList != 0)
        {
            delete m_pNormalList;
            m_pNormalList = 0;
        }
        m_pNormalList = list;
    }

    MD2Model::NormalList* MD2Model::getNormalList() const
    {
        return m_pNormalList;
    }

    void MD2Model::setTexCoordList(TexCoordList *list)
    {
        if (m_pTexCoordList != 0)
        {
            delete m_pTexCoordList;
            m_pTexCoordList = 0;
        }
        m_pTexCoordList = list;
    }

    MD2Model::TexCoordList* MD2Model::getTexCoordList() const
    {
        return m_pTexCoordList;
    }

    void MD2Model::setVertexIndexList(IndexList *list)
    {
        if (m_pVertexIndexList != 0)
        {
            delete m_pVertexIndexList;
            m_pVertexIndexList = 0;
        }
        m_pVertexIndexList = list;
    }

    MD2Model::IndexList* MD2Model::getVertexIndexList() const
    {
        return m_pVertexIndexList;
    }

    void MD2Model::setNormalIndexList(IndexList *list)
    {
        if (m_pNormalIndexList != 0)
        {
            delete m_pNormalIndexList;
            m_pNormalIndexList = 0;
        }
        m_pNormalIndexList = list;
    }

    MD2Model::IndexList* MD2Model::getNormalIndexList() const
    {
        return m_pNormalIndexList;
    }

    void MD2Model::setTexCoordIndexList(IndexList *list)
    {
        if (m_pTexCoordIndexList != 0)
        {
            delete m_pTexCoordIndexList;
            m_pTexCoordIndexList = 0;
        }
        m_pTexCoordIndexList = list;
    }

    MD2Model::IndexList* MD2Model::getTexCoordIndexList() const
    {
        return m_pTexCoordIndexList;
    }

    void MD2Model::setTexture(Texture* const texture)
    {
        if (m_pTexture != 0)
        {
            delete m_pTexture;
            m_pTexture = 0;
        }
        m_pTexture = texture;
    }

    Texture* MD2Model::getTexture() const
    {
        return m_pTexture;
    }

    void MD2Model::setFrameNum(const uint32_t n)
    {
        m_iFrameNum = n;
    }

    uint32_t MD2Model::getFrameNum() const
    {
        return m_iFrameNum;
    }

    void MD2Model::setFrameSize(const uint32_t n)
    {
        m_iFrameSize = n;
    }

    uint32_t MD2Model::getFrameSize() const
    {
        return m_iFrameSize;
    }

    uint32_t MD2Model::getVertexAmount() const
    {
        return m_pVertexList->size();
    }

    uint32_t MD2Model::getNormalAmount() const
    {
        return m_pNormalList->size();
    }

    uint32_t MD2Model::getTexCoordAmount() const
    {
        return m_pTexCoordList->size();
    }

    uint32_t MD2Model::getTriangleAmount() const
    {
        return (m_pVertexIndexList->size()) / 3;
    }

    MD2Model::~MD2Model()
    {
        if (m_pVertexList != 0)
        {
            delete m_pVertexList;
            m_pVertexList = 0;
        }
        if (m_pNormalList != 0)
        {
            delete m_pNormalList;
            m_pNormalList = 0;
        }
        if (m_pTexCoordList != 0)
        {
            delete m_pTexCoordList;
            m_pTexCoordList = 0;
        }
        if (m_pVertexIndexList != 0)
        {
            delete m_pVertexIndexList;
            m_pVertexIndexList = 0;
        }
        if (m_pNormalIndexList != 0)
        {
            delete m_pNormalIndexList;
            m_pNormalIndexList = 0;
        }
        if (m_pTexCoordIndexList != 0)
        {
            delete m_pTexCoordIndexList;
            m_pTexCoordIndexList = 0;
        }
        if (m_pTexture != 0)
        {
            delete m_pTexture;
            m_pTexture = 0;
        }
    }
}

